﻿<UserControl x:Class="GemGui.SccEnvironmentsControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:commands="clr-namespace:GemGui.Commands"
             xmlns:converters="http://schemas.kent.boogaart.com/converters"
             xmlns:gemGui="clr-namespace:GemGui"
             mc:Ignorable="d"
             Height="{Binding Height, ElementName=StkContainer}"
             Width="{Binding Width, ElementName=StkContainer}">
  <UserControl.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <commands:ProcessExecutionConverter x:Key="ProcessExecutionConverter" />
    <commands:EditCommandParametersConverter x:Key="EditCommandParametersConverter" />
  </UserControl.Resources>
  
  <StackPanel Name="StkContainer"
              Margin="4">
    <TextBlock Text="GEM Identified SCC Environments"
               FontWeight="Bold"/>
    <TextBlock Text="{Binding EnvironmentsStatus}"
               FontSize="11"/>
    <ListBox HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Top"
             ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"
             Visibility="{Binding HasEnvironments, Converter={StaticResource BooleanToVisibilityConverter}}"
             HorizontalContentAlignment="Stretch"
             ItemsSource="{Binding EnvironmentsView}">
      <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
          <Setter Property="Background" Value="{Binding Path=NonHoverColor}" />
          <Setter Property="ContextMenu">
            <Setter.Value>
              <!-- The setting on the ContextMenu.DataContext is due to the fact that the ContextMenu is immutable in
                   regard to the DataContext, which leads to bizarre functionality. See also:
                   http://www.codeproject.com/Articles/162784/WPF-ContextMenu-Strikes-Again-DataContext-Not-Upda -->
              <ContextMenu
                DataContext="{Binding PlacementTarget.DataContext,
		            RelativeSource={RelativeSource Self}}">
                <!--<MenuItem Header="Edit"
                          Command="{Binding Container.EditCustomItemCommand}">
                  <MenuItem.CommandParameter>
                    <MultiBinding Converter="{StaticResource EditCommandParametersConverter}">
                      <Binding Source="{x:Static commands:EditCommandModes.InvokeEditMode}" />
                      <Binding />
                      <Binding ElementName="TxtCustomInfo" />
                    </MultiBinding>
                  </MenuItem.CommandParameter>
                </MenuItem>
                <Separator />-->
                <MenuItem Header="Explore Here"
                          Command="{Binding Container.ExecutableRunCommand}">
                  <MenuItem.CommandParameter>
                    <MultiBinding Converter="{StaticResource ProcessExecutionConverter}">
                      <Binding Source="explorer.exe" />
                      <Binding Path="FolderName" Converter="{converters:FormatConverter '{}&quot;{0}&quot;'}" />
                    </MultiBinding>
                  </MenuItem.CommandParameter>
                </MenuItem>
                <Separator />
                <MenuItem Header="Copy Path"
                          Command="{Binding Container.CopyTextCommand}"
                          CommandParameter="{Binding FolderName, Converter={converters:FormatConverter '{}&quot;{0}&quot;'}}"/>
                <MenuItem Header="Copy Info"
                          Command="{Binding Container.CopyTextCommand}"
                          CommandParameter="{Binding FolderSccInformation}" />
                <Separator />
                <!-- MenuItem Header="Properties"
                          / -->
              </ContextMenu>
            </Setter.Value>
          </Setter>
          <Setter Property="Focusable" Value="False" />
          <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="Background" Value="Gold" />
            </Trigger>
          </Style.Triggers>
        </Style>
      </ListBox.ItemContainerStyle>

      <ListBox.ItemTemplate>
        <DataTemplate>
          <gemGui:EnvironmentControl />
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
  </StackPanel>
</UserControl>
